<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>场地管理</title>
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<link rel="stylesheet" href="css/homePage.css">
	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/flexible.css">
	<link rel="stylesheet" href="css/vant.css">
	<script src="js/vue/vue.js"></script>
	<script src="js/vue/axios.js"></script>
	<script src="js/vue/vant.js"></script>
	<script src="js/glabe.js"></script>
	<script src="js/jquery.md5.js"></script>
	<script src="js/vue/qs.js"></script>
	<script src="js/jquery-3.3.1.min.js"></script>
	<script src="js/flexible.js"></script>
</head>
<body>
	<div class="customer_type" id="app">
		<form action="" method="">
			<table class="customer_type_table">
				<tbody>
					<tr class="clearfix">
						<td><span>场地名称</span></td>
						<td>
							<input type="text" name="" placeholder="请输入场地名称" class="customerphone" v-model="Space_name">
						</td>
					</tr>
					<tr class="clearfix">
						<td><span>场地位置</span></td>
						<td>
							<input type="text" name="" placeholder="请输入场地位置" class="customername" v-model="Into">
						</td>
					</tr>
					<tr class="clearfix">
						<td><span>容纳人数</span></td>
						<td>
							<input type="text" oninput = "value=value.replace(/[^\d]/g,'')" name="" placeholder="请输入容纳人数" class="customername" v-model="Num">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
		<div class="sub_btn_div">
			<input type="submit" name="" value="" class="sub_btn" readonly="readonly" @click="submit()">
		</div>
	</div>
	<script>
	var app = new Vue({
		el: '#app',
		data: {
			//场地名字
			Space_name:null,
			//场地位置(场地简介)
			Into:null,
			//容纳人数
			Num:null,
			//场地状态
			State:0,
			//id
			id:null
		},
		created() {
			//获取路由参数
			let id = getUrlQueryString('id');
			this.id = id;
			//获取修改的场地数据
			if (id) {
				//修改
				axios.get('mobileapi/boss/space.php?act=edit&id='+id).then(res=>{
					if (res.data.code == 200) {
						let siteData = res.data.data;
						this.Space_name = siteData.Space_name;
						this.Into = siteData.Into;
						this.Num = siteData.Num;
						this.State = siteData.State;
					}else{
						vant.Toast(res.data.msg);
					}
				}).catch(err=>{
					vant.Toast('请求发送失败，请重试')
				})
			}
			
		},
		methods: {
			//提交按钮
			submit(){
				//表单验证
				if (this.Space_name == null || this.Space_name == '') {
					vant.Toast('请输入场地名称');
					return false;
				}	
				if (this.Into == null || this.Into == '') {
					vant.Toast('请输入场地位置');
					return false;
				}	
				if (this.Num == null || this.Num == '') {
					vant.Toast('请输入容纳人数');
					return false;
				}
				//判断是添加还是修改
				if (this.id) {
					//修改
					let from = JSON.stringify({
						Space_name:this.Space_name,
						Num:this.Num,
						Into:this.Into,
						State:this.State,
						id:this.id
					});
					let sign = md5(from);
					let obj = {
						from,
						sign
					};
					axios.post('mobileapi/boss/space.php?act=editgo',Qs.stringify(obj)).then(res=>{
						if (res.data.code == 200) {
							vant.Toast('修改场地成功');
							setTimeout(()=>{
								// history.go(-1);
								location.href = "siteManagement.html";
							});
						}else{
							vant.Toast(res.data.msg);
						}
					}).catch(err=>{
						vant.Toast('请求发送失败，请重试');
					});
				}else{
					//添加
					let from = JSON.stringify({
						Space_name:this.Space_name,
						Num:this.Num,
						Into:this.Into,
						State:this.State
					});
					let sign = md5(from);
					let obj = {
						from,
						sign
					};
					axios.post('mobileapi/boss/space.php?act=add',Qs.stringify(obj)).then(res=>{
						if (res.data.code == 200) {
							vant.Toast('添加场地成功');
							setTimeout(()=>{
								// history.go(-1);
								location.href = "siteManagement.html";
							});
						}else{
							vant.Toast(res.data.msg);
						};
					}).catch(err=>{
						vant.Toast('请求发送失败，请重试');
					});
				}
				
			}
		}
	})
	</script>
</body>
</html>